package fr.mma.livraison.controler;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.util.DAOBase;

import fr.mma.livraison.model.Admin;

public class AdminDao extends DAOBase {

    static {
        ObjectifyService.register(Admin.class);
    }

    public Admin getOrCreate(long id)
    {
    	Admin found = ofy().find(Admin.class, id);
        if (found == null)
            return new Admin(id);
        else
            return found;
    }
    
    public boolean isAdmin(String name) {
    	return ofy().query(Admin.class).filter("name", name).count() > 0;
    }
    
    public List<Admin> getAll() {
    	List<Admin>alldAdmin = new ArrayList<Admin>();
		for (Admin admin : ofy().query(Admin.class)) {
			alldAdmin.add(admin);
		} 
		return alldAdmin;
    }
    
    public void save(Admin admin) {
    	ofy().put(admin);
    }
	
	
}
